﻿@model OpenMVCRM.ViewModels.AddClientAddressViewModel
@{
    ViewBag.Title = "Edit Address -" + Model.ClientName;
}

<fieldset>

<div class="divContainer">
<div class="divEditBar">
<div class="divBreadCrump">
      <span>You are here : </span>
      @Html.ActionLink("Clients", "Index") <span class="breadCrumpSeperator"></span>
      @Html.ActionLink(Model.ClientName, "View", new { @id = Model.ClientId }) <span class="breadCrumpSeperator"></span>
      Edit Address
</div>
<div class="divEditRightLinks"> 
     @Html.ActionLink("Delete", "Delete")
</div>
</div>

<div class="divClientInfo">

    <h2>@Model.ClientName</h2>
</div>
 <h3>Address Information</h3>
<div class="divCreateFormSub">

   @using (Html.BeginForm())
   {
    <div class="editor-label">
         @Html.LabelFor(m => m.AddressLine1)
    </div>
    <div class="editor-field">
         @Html.TextBoxFor(x => x.AddressLine1)
         @Html.ValidationMessageFor(m => m.AddressLine1)
    </div>   
    <div class="editor-label">
        @Html.LabelFor(m => m.AddressLine2)
    </div>
    <div class="editor-field">
        @Html.TextBoxFor(x => x.AddressLine2)
        @Html.ValidationMessageFor(m => m.AddressLine2)
    </div>
           <div class="editor-label">
     @Html.LabelFor(m => m.Countries)
   </div>
       <div class="editor-field">
       @Html.DropDownListFor(x => x.SelectedCountryID, new SelectList(Model.Countries, "CountryID", "CountryName"), "Select")
    </div>
    <div class="editor-label">
     @Html.LabelFor(m => m.SelectedStateID)
   </div>
       <div class="editor-field">
       @Html.DropDownListFor(x => x.SelectedStateID, new SelectList(Model.States, "StateID", "StateName"), "Select")   
    </div>
    <div class="editor-label">
        @Html.LabelFor(m => m.City)
    </div>
    <div class="editor-field">
        @Html.TextBoxFor(x => x.City)
        @Html.ValidationMessageFor(m => m.City)
    </div>
    <div class="editor-label">
        @Html.LabelFor(m => m.ZipCode)
    </div>
    <div class="editor-field">
        @Html.TextBoxFor(x => x.ZipCode)
        @Html.ValidationMessageFor(m => m.ZipCode)
    </div>
    <div class="editor-label">
        @Html.LabelFor(m => m.IsPrimary)
    </div>
    <div class="editor-field">
        @Html.CheckBoxFor(x => x.IsPrimary)       
    </div>
    <p>
        <input type="submit" value="Save" />
    </p>
    @Html.HiddenFor(x => x.ClientId)
    @Html.HiddenFor(x => x.AddressId)
   }

 </div>

 </div>
</fieldset>

<script type="text/javascript">
    $(function () {
       
        $("#SelectedCountryID").change(function () {
            var self = $(this);
            var items="";
            $.getJSON("@Url.Action("Index", "States")?id="+self.val(),function(data){
              $.each(data,function(index,item){
                items+="<option value='"+item.StateID+"'>"+item.StateName+"</option>";
              });
              $("#SelectedStateID").html(items);
            });
        });
    });
</script>